home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINWORDS / WE_20N.ZIP / WEEXTSRC.ZI_ / WE_EXT.C < prev    next >
C/C++ Source or Header  |  1993-01-13  |  14KB  |  421 lines

  1. /*-------------------------------------------------------------------------*\
  2.  |                                                                         |
  3.  |                                                                         |
  4.  |  WE_EXT.C - A Sample DLL Extension Processor for WinEdit                |
  5.  |                                                                         |
  6.  |                                                                         |
  7. \*-------------------------------------------------------------------------*/
  8. #define STRICT
  9. #define _WINDLL
  10. #include <windows.h>
  11. #include "we_ext.h"
  12. #include "private.h"
  13. #include <string.h>
  14.  
  15. #define NOREF(a)  {a=a;}
  16.  
  17. HMENU hTrackMenu;
  18. BOOL bWait=TRUE;
  19. BOOL bCapture=TRUE;
  20. char szCommand[256];
  21.  
  22. /*
  23.  * JLD-12/9/92 Added this to setup the default GREP string, which recurs if
  24.  * no work is under the cursor.  See line 204.
  25.  */
  26.  
  27. char GLOB_GrepCmd[256] = {"tee.com fgrep.com -M %s *.c"};
  28.  
  29. /*-------------------------------------------------------------------------*\
  30.  |                                                                         |
  31.  |  Function:   WE_ExtensionProc                                           |
  32.  |                                                                         |
  33.  |  Purpose:    WinEdit calls this function with the WEN_* messages and    |
  34.  |              whenever a user-defined menu item or accelerator is        |
  35.  |              accessed.                                                  |
  36.  |                                                                         |
  37.  |  Parameters: HWND hWnd   - WinEdit's window handle                      |
  38.  |                                                                         |
  39.  |              UINT wParam - Message ID.  If wParam is >= WE_EXTFIRST,    |
  40.  |                            the DLL is being requested to perform the    |
  41.  |                            user-defined action.                         |
  42.  |                                                                         |
  43. \*-------------------------------------------------------------------------*/
  44. UINT FAR PASCAL WE_ExtensionProc(HWND hWnd,     /* WinEdit's window handle */
  45.                                  HANDLE hInst,  /* instance identifier     */
  46.                                  UINT wParam,   /* command ID              */
  47.                                  LONG lParam)   /* additional information  */
  48.    {
  49.  
  50.    switch (wParam)
  51.       {
  52.  
  53.       case WEN_LOADMENU:
  54.  
  55.          /*  This is the menu WinEdit will display when there
  56.           *  is at least one document window open.  Return NULL
  57.           *  to use the default WinEdit menu.
  58.           *
  59.           */
  60.  
  61.          return (UINT)LoadMenu(hInst, "MyMenu");
  62.          break;
  63.  
  64.       case WEN_LOADSHORTMENU:
  65.  
  66.          /*  this is the menu WinEdit will display when there
  67.              *  are no document windows open.  Return NULL
  68.              *  to use the default WinEdit menu.
  69.              *
  70.              */
  71.    
  72.             return (UINT)LoadMenu(hInst, "MyShortMenu");
  73.             return NULL;
  74.             break;
  75.    
  76.       case WEN_LOADACCELS:
  77.  
  78.          /*  To re-define the WinEdit command keys, load your
  79.           *  own accelerator table here.  Return NULL to
  80.           *  use the default WinEdit accelerators.
  81.           *
  82.           */
  83.  
  84.          return (UINT)LoadAccelerators (hInst,"MyAccels");
  85.          break;
  86.  
  87.       case WEN_GETWINDOWMENU:
  88.  
  89.          /*  WinEdit needs the handle of the submenu to
  90.           *  append MDI document names to.  The hWnd parameter
  91.           *  is used to send the handle to the main menu.
  92.           *  This message will not be sent if you return
  93.           *  NULL to the WEN_LOADMENU message.
  94.           */
  95.          return (UINT)GetSubMenu ((HMENU)hWnd, WINDOWMENU);
  96.          break;
  97.  
  98.       case WEN_GETMACROMENU:
  99.  
  100.          /*  WinEdit needs the handle of the submenu to
  101.           *  append macro names to.  The hWnd parameter
  102.           *  is used to send the handle to the main menu.
  103.           *  This message will not be sent if you return
  104.           *  NULL to the WEN_LOADMENU message.
  105.           */
  106.          return (UINT)GetSubMenu ((HMENU)hWnd, MACROMENU);
  107.          break;
  108.  
  109.          /*  WinEdit sends right button clicks to the
  110.           *  extension processor.  lParam contains the
  111.           *  x and y coordinates of the mouse cursor,
  112.           *  in screen coordinates.
  113.           */
  114.       case WEN_RBUTTONDOWNS:
  115.          edHelpKeyWord(hWnd);
  116.          break;
  117.  
  118.       case WEN_RBUTTONDOWN:
  119.  
  120.          if (!hTrackMenu)
  121.             {
  122.  
  123.             hTrackMenu = CreatePopupMenu();
  124.             if (!hTrackMenu)
  125.                break;
  126.  
  127.  /* JLD 12/9/92 - Changed these labels to the Ctrl-V,X,Z, etc. which matches the 
  128.   *               current pull-down labels.
  129.   *               Also changed F3 to Previous error, F4 to next error, which seems
  130.   *               more consistent.  I left Re-Do as Ctrl-Backspace. 
  131.   *               Added Close to this menu.
  132.   *               Added Ctrl L as a synonym for Ctrl-F5.  (similar to Wordstar)
  133.   */ 
  134.                
  135.             AppendMenu(hTrackMenu,MF_STRING,IDM_FILEOPEN,"&Open...\tF3");
  136.             AppendMenu(hTrackMenu,MF_STRING,IDM_FILESAVE,"&Save\tF2");                 
  137.             AppendMenu(hTrackMenu,MF_STRING,IDM_WINDOWCLOSE,"&Close\tCtrl+F4");                
  138.             AppendMenu(hTrackMenu,MF_STRING,IDM_FILEPRINT,"&Print\tF9");                
  139.             AppendMenu(hTrackMenu,MF_SEPARATOR,0,0L);
  140.             AppendMenu(hTrackMenu,MF_STRING,IDM_EDITUNDO,"&Undo\tCtrl+Z");           
  141.             AppendMenu(hTrackMenu,MF_STRING,IDM_EDITREDO,"&Redo\tCtrl+BkSp");          
  142.             AppendMenu(hTrackMenu,MF_SEPARATOR,0,0L);
  143.             AppendMenu(hTrackMenu,MF_STRING,IDM_EDITCUT,"Cu&t\tCtrl+X");     
  144.             AppendMenu(hTrackMenu,MF_STRING,IDM_EDITCOPY,"&Copy\tCtrl+C");            
  145.             AppendMenu(hTrackMenu,MF_STRING,IDM_EDITPASTE,"&Paste\tCtrl+V");          
  146.             AppendMenu(hTrackMenu,MF_SEPARATOR,0,0L);
  147.             AppendMenu(hTrackMenu,MF_STRING,IDM_SEARCHFIND,"&Find...\tF5");              
  148.             AppendMenu(hTrackMenu,MF_STRING,IDM_SEARCHNEXT,"&Repeat Last Find\tCtrl+F5|L");
  149.             AppendMenu(hTrackMenu,MF_STRING,IDM_SEARCHCHANGE,"&Change...\tF6");            
  150.             AppendMenu(hTrackMenu,MF_SEPARATOR,0,0L);
  151.             AppendMenu(hTrackMenu,MF_STRING,IDM_SEARCHPREVERR,"&Previous Error\tShift+F3");    
  152.             AppendMenu(hTrackMenu,MF_STRING,IDM_SEARCHNEXTERR,"&Next Error\tShift+F4");
  153.             AppendMenu(hTrackMenu,MF_SEPARATOR,0,0L);
  154.             AppendMenu(hTrackMenu,MF_STRING,IDM_HELPKEYWORDS,"&Key Word Help\tShift+F1");  
  155.             }
  156.             
  157.          if (hTrackMenu)
  158.             {
  159.             POINT pt;
  160.  
  161.             pt = MAKEPOINT(lParam);
  162.             TrackPopupMenu(hTrackMenu,0,pt.x-10,pt.y-6,0,hWnd,0L);
  163.             }
  164.             
  165.          return TRUE;   
  166.          break;
  167.  
  168.       case WEN_END:
  169.  
  170.          /*  WinEdit is shutting down.  Do any clean-up processing
  171.           *  here.
  172.           */
  173.          if (hTrackMenu)
  174.             {
  175.             DestroyMenu(hTrackMenu);
  176.             hTrackMenu = (HMENU)NULL;
  177.             }
  178.          return TRUE;
  179.          break;
  180.  
  181.       case WEN_INITMENU:
  182.  
  183.          /*  This message is sent before showing any drop down
  184.           *  menu items.  Respond by setting any checkmarks,
  185.           *  graying any inapplicable items, etc.
  186.           *
  187.           */
  188.          return InitMenu(hWnd);
  189.          break;
  190.  
  191.  
  192.       /*  You can define your own commands in the range
  193.        *  WE_EXTFIRST to WE_EXTLAST that can be attached to
  194.        *  menu items or accelerators.
  195.        */
  196.  
  197.       case EXT_GREP:
  198.          {
  199.          char szWord[64];
  200.          edEditGetCurrentWord(hWnd,szWord,63);
  201.          if (szWord[0])
  202.             wsprintf(szCommand,"tee.com fgrep.com -M %s *.c",(LPSTR)szWord);
  203.          else
  204.             wsprintf(szCommand,GLOB_GrepCmd);  /* JLD 12/9/92 see beginning of file */
  205.  
  206. /* JLD 12/9/92 this *remembers* the last s